import request from "@/utils/request.ts";
import Enum from "@/api/shopCartApi/enum.ts";
import type { ShopCart, Stock } from "@/types/shopCartTypes/shopCartTypes.ts";
import type { Response } from "@/types/commonTypes/commonTypes.ts";
import type { Sku, Spec } from "@/types/detailTypes/detailTypes.ts";
/*获取最新的商品信息的接口*/
export const fetchNewCartGoodsAPI = (skuId: string): Promise<Response<Stock>> => request.get<any, Response<Stock>>(`${Enum.fetchNewCartGoods}/${skuId}`);
/*获取商品SKU信息的接口*/
export const fetchGoodSkuAPI = (skuId: string): Promise<Response<{ skus: Sku[], specs: Spec[] }>> => request.get<any, Response<{ skus: Sku[], specs: Spec[] }>>(`${Enum.fetchGoodSku}/${skuId}`);
/*将本地购物车和线上购物车合并的接口*/
export const mergeCartAPI = (cartList: any): Promise<Response<string>> => request.post<any, Response<string>>(Enum.mergeCart, cartList);
/*获取购物车商品列表的接口*/
export const fetchShopCartListAPI = (): Promise<Response<ShopCart[]>> => request.get<any, Response<ShopCart[]>>(Enum.fetchShopCart);
/*加入购物车的接口*/
export const addShopCartAPI = (skuId: string, count: number): Promise<Response<ShopCart>> => request.post<any, Response<ShopCart>>(Enum.addShopCart, { skuId, count });
/*删除购物车商品的接口*/
export const deleteShopCartAPI = (skuId: string[]): Promise<Response<boolean>> => request.delete<any, Response<boolean>>(Enum.deleteShopCart, { data: { ids: skuId } });
/*修改购物车商品选中状态和数量的接口*/
export const changeSelectOrCountAPI = ({ id, selected, count }: { id: string, selected?: boolean, count?: number }): Promise<Response<ShopCart>> => request.put<any, Response<ShopCart>>(`${Enum.changeSelectOrCount}/${id}`, { count, selected });
/*全选和取消全选的接口*/
export const changeSelectAllAPI = (selected: boolean, ids: string[]): Promise<Response<any>> => request.put<any, Response<any>>(Enum.changeSelectAll, { selected, ids });
